#!/bin/sh

case "$1" in
    install)
        # When we first install mod_spdy, modify ssl.load.
        if [ -f "@@APACHE_CONFDIR@@/ssl.load" ]; then
          if ! grep -q 'MOD_SPDY' @@APACHE_CONFDIR@@/ssl.load; then
            # First, comment out all lines in the file, using a special prefix.
            # We will look for that prefix later when we uninstall.
            sed --in-place 's/^.*$/#ORIG# &/' @@APACHE_CONFDIR@@/ssl.load
            # Next, append a new LoadModule line to the file, with some
            # explanitory comments.  The first line we append contains the
            # magic marker "MOD_SPDY", which we look for in the postrm script
            # so that we can remove the below text when we uninstall.
            cat >> @@APACHE_CONFDIR@@/ssl.load <<EOF
########## MOD_SPDY CHANGES BELOW ##########
# If mod_spdy is uninstalled, this file will be restored to its original form
# by deleting everything below here and uncommenting everything above.

# Using mod_spdy requires using a patched version of mod_ssl that provides
# hooks into the Next Protocol Negotiation (NPN) data from the SSL handshake.
# Thus, the mod_spdy package installs mod_ssl_with_npn.so, which is exactly
# mod_ssl but with the following (small) patch applied:
#   https://issues.apache.org/bugzilla/attachment.cgi?id=27969

LoadModule ssl_module @@APACHE_MODULEDIR@@/mod_ssl_with_npn.so
EOF
          fi
        fi
    ;;
    upgrade|abort-upgrade)
    ;;
    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0
